<%@ page language="java" pageEncoding="UTF-8"%>
<jsp:directive.page import="edu.ntu.im.p2ptrade.P2PTrade"/>

<html>
<title>user_list</title>

<script type="text/javascript" src="/p2ptrade/js/dialog.js"></script>
<script type="text/javascript" src="/p2ptrade/js/peers.js"></script>
<script type="text/javascript" src="/p2ptrade/js/json.js"></script>
<script type="text/javascript" src="/p2ptrade/js/ajax.js"></script>
<script type="text/javascript" src="/p2ptrade/js/item.js"></script>
<script type="text/javascript" src="/p2ptrade/js/tray.js"></script>
<script type="text/javascript" src="/p2ptrade/js/template.js"></script>
<script type="text/javascript" src="/p2ptrade/js/request.js"></script>
<script type="text/javascript" src="/p2ptrade/js/prototype.js"></script>
<script>
var me = '<%=P2PTrade.getInstance().getPeerName()%>'	
var peerMgt = new PeerManager("peers");
var whosItem;
var getAll = true;

function updateBackEnd(){
   var req = createAjaxRequest2(function(result){

          if (result.success){
				if (result.result.currentPeers){
				    //currentPeers = result.result.currentPeers;
					/*
					for(var name in currentPeers){
						if(currentPeers[name].name)
						{
							alert(currentPeers[name].name);
					   		//$(currentPeers[name].name+"_input").peerName=currentPeers[name].name;
					   	}   
					}
					*/

					peerMgt.update(result.result.currentPeers);
				}
				getAll = false;
          }
        });
       
	var url = "/p2ptrade/informFrontEnd.do?getAll="+getAll;

	req.open("GET", url , true);
	req.send(null);
}

setTimeout("updateBackEnd()",50);
setInterval("updateBackEnd()", 5000);

</script>

<link href="../css/css.css" rel="stylesheet" type="text/css">

<body>

<div align="center"><jsp:include page="/top.tpl" />
<br>
<table align="center">
	<tr><td colspan="2" class="header">Online User List</td></tr>
	<tr>
		<td><div id="peers"></div></td>
	</tr>
</table>

<textarea id="peerTemplate" style="display:none">
{for p in peers}
  <span style="cursor:pointer" id="\${p.name}_div" ><img src="http://\${p.photoURL}" width="50" height="50">  \${p.nickName}</span> <br>
{/for}
</textarea>

</div>
</body>
</html>